<?php
	$hfbcats 	= getHFBCats();
	$headers 	= getHeaders();
	$buttons	= getButtonsList();
	$iconsets	= getIconSetList();
	
	if($_REQUEST['item'] > 0)
	{ $item['id'] = $_REQUEST['item']; }
	if($item['id'] > 0)
	{ 
		$item 			= getHeaderAdmin($item['id']); 
		$incats 		= getInHFBCats($item['id'], 1);
	}
	switch ($_POST['action'])
	{
		case 'new_item':
			if($_POST['name'] != '')
			{ addHeader($_POST['name']); }
			$i=0;
			if($_POST['hdr_id'])
			{
				foreach($_POST['hdr_id'] as $id)
				{
					updateHeader($id, $_POST['hdr_name'][$i], $_POST['hdr_height'][$i], $_POST['hdr_imagefont'][$i], '');
					$i++;
				}
			}
			if($_POST['load_css'] > 0)
			{ reloadHFBTypeCss($_POST['load_css']); }
			if($_POST['activate'] > 0)
			{ setTableActive($_POST['activate'], 'com_headers', 1); }
			if($_POST['deactivate'] > 0)
			{ setTableActive($_POST['deactivate'], 'com_headers', 0); }
			if($_POST['delete_header'] > 0)
			{ deleteHeader($_POST['delete_header']); } 
			break;
		case 'editor':
			if($item['id'] > 0)
			{
				updateHeader($item['id'], $_POST['name'], $_POST['height'], $_POST['imagefont'], $_POST['button'], $_POST['icon']);
				uploadHeaderImages($item['id']);
				if(($_POST['delete_l'] == "1") && ($item['l_image'] != ""))
				{ deleteHeaderImage($item['id'], 'l_image', $item['l_image']); }
				if(($_POST['delete_bg'] == "1") && ($item['image'] != ""))
				{ deleteHeaderImage($item['id'], 'image', $item['image']); }
				if(($_POST['delete_bg2'] == "1") && ($item['image2'] != ""))
				{ deleteHeaderImage($item['id'], 'image2', $item['image2']); }
				if($_POST['add_to_cat'] > 0)
				{ addItemToCat($item['id'], 1, $_POST['add_to_cat']);}
				if($_POST['rem_from_cat'] > 0)
				{ removeItemFromCat($item['id'], 1, $_POST['rem_from_cat']);}
				
				updateCss(1,$item['id'],'div.com_header div.ch_'.$item['id'], $_POST['ch']);
				updateCss(1,$item['id'],'div.com_header div.ch_'.$item['id'].' div.ch_left', $_POST['ch_left']);
				updateCss(1,$item['id'],'div.com_header div.ch_'.$item['id'].' div.ch_right', $_POST['ch_right']);
				updateCss(1,$item['id'],'div.com_header div.ch_'.$item['id'].' div.ch_center', $_POST['ch_center']); 
				updateCss(1,$item['id'],'div.com_header div.ch_'.$item['id'].' div.ch_content', $_POST['ch_content']); 
				updateCss(1,$item['id'],'div.com_header div.ch_'.$item['id'].' .ch_icon', $_POST['ch_icon']); 
				updateCss(1,$item['id'],'div.com_header div.ch_'.$item['id'].' h2', $_POST['h2']); 
				updateCss(1,$item['id'],'div.com_header div.ch_'.$item['id'].' .ch_txt', $_POST['ch_txt']); 
				updateCss(1,$item['id'],'div.com_header div.ch_'.$item['id'].' .ch_txt2', $_POST['ch_txt2']); 
				updateCss(1,$item['id'],'div.com_header div.ch_'.$item['id'].' .ch_txt3', $_POST['ch_txt3']); 
				updateCss(1,$item['id'],'div.com_header div.ch_'.$item['id'].' .ch_buttons', $_POST['ch_buttons']); 
				
				reloadHFBTypeCss(1);
			}
			break;
	}
	if($_REQUEST['cat'] > 0)
	{ $headers = getHeaders($_REQUEST['cat']); }
	else
	{ $headers = getHeaders(); }
	if($item['id'] > 0)
	{ 
		$item = getHeaderAdmin($item['id']); 
		$incats = getInHFBCats($item['id'], 1);
	}
?>